<?php
/**
 * form控制器
 *
 * @package     Include  (controller)
 * @author      hary <hary@taomee.com>
 * @version     $ID 2010-3-31 $
 */
class Admin_file extends Controller
{
	private $result;

	/**
	 * 构造函数
	 */
	function __construct()
	{
		parent::__construct();

		$this->loadModel("file_model");
		$this->tpl->template_dir = SYS_PATH  . 'template/admin/file/';
	}

	/**
	 * 默认执行方法
	 *
	 * @return
	 */
	function index()
	{
		$this->getFiles();
	}
	
	/**
	 * 根据关键字获取图片
	 * @return max
	 */
	function getFiles(){
		
		$page    = max(1,$this->in_var['page']);
		$keyword = $this->in_var['keyword'];
		
		$files = $this->file_model->getFiles($keyword,$page);
		
		$page_info = $this->file_model->getPageInfo('/admin'.get_url(strtolower(__CLASS__), __FUNCTION__, 'page={Page}'), 3);
		
		$this->result['files'] = $files;
		
		$this->tpl->assign("result",$this->result);
		$this->tpl->assign("page_info",$page_info);
		
		$this->tpl->display("file_panel.html");
		
	}
	/**
	 * 上传文件
	 * @return max
	 */
	function uploadFile(){
		
		$file = $this->file_model->uploadFile();
		
		if($file)
		{
			$this->tpl->assign('file',$file);
			$this->tpl->display("file_info.html");
		}
		else
		{
			exit("upload failed");
		}
	}

	/**
	 * 删除单个文件
	 * @return json
	 */
	function delFile(){

		$id = intval($this->in_var['id']);

		$result = $this->file_model->delFileById($id);

		if($result)
		{
			exit("delete success");
		}
		else
		{
			exit("delete failed");
		}
	}

}